<?php
require_once 'DBConnecter.inc';
class DailyReport extends DBConnecter {
	public $search_dt = ""; // 날짜
	public $mem_id = ""; // 사원번호
	public $mem_nm = ""; // 이름
	public $positions = ""; // 직급
	public $license_plate = ""; // 차량등록번호판
	public $car_id = ""; // 차량식별번호
	public $cusm_cd = ""; // 거래처코드
	public $brno = ""; // 근무점포
	public $attend_tp = ""; // 출근여부
	public $subs_amt = ""; // 용차비용
	public $subs_firm = ""; // 용차업체명
	public $etc_amt_1 = ""; // 기타 비용1
	public $etc_amt_2 = ""; // 기타 비용2
	public $close_deduct = ""; // 휴무공제
	public $car_soyu_tp = ""; // 기사구분
	public $car_soyu_nm = ""; // 기사구분명
	public $note = ""; // 메모
	public $arrSize = 0;
	function __construct() {
		$this->connectDB ();
		// $this->selectDB ( 'devdog' );
	}
	public function tablePrint($isSuperAdmin) {
		if ($isSuperAdmin) {
			echo "<tr onclick=\"location.href='./employee_detail.php?pageType=2&id=" . $this->mem_id . "'\">";
		} else {
			echo "<tr onclick=\"location.href='./daily_report.php?id=" . $this->mem_id . "&date=" . $this->search_dt . "'\">";
		}
		
		echo "<td>" . $this->search_dt . "</td>";
		echo "<td>" . $this->mem_id . "</td>";
		echo "<td>" . $this->mem_nm . "</td>";
		echo "<td>" . $this->positions . "</td>";
		echo "<td>" . $this->license_plate . "</td>";
		echo "<td>" . $this->car_id . "</td>";
		echo "<td>" . $this->cusm_cd . "</td>";
		echo "<td>" . $this->brno . "</td>";
		echo "<td>" . $this->attend_tp . "</td>";
		echo "</tr>";
	}
	public function admin_tablePrint($isSuperAdmin) {
		if ($isSuperAdmin) {
			echo "<tr onclick=\"location.href='./employee_detail.php?pageType=2&id=" . $this->mem_id . "'\">";
		} else {
			echo "<tr onclick=\"location.href='./daily_report.php?id=" . $this->mem_id . "'\">";
		}
		
		echo "<td>" . $this->search_dt . "</td>";
		echo "<td>" . $this->mem_id . "</td>";
		echo "<td>" . $this->mem_nm . "</td>";
		echo "<td>" . $this->attend_tp . "</td>";
		echo "<td>" . $this->note . "</td>";
		echo "</tr>";
	}
	public function search4table($isSuperAdmin, $fr_date, $to_date, $op, $value) {
		$sql = "CALL " . self::CONST_DB . ".daily_accounts_search('2', '" . $fr_date . "','" . $to_date . "','" . $op . "','" . $value . "');select @out_err_cd, @out_err_msg;";
		// $retval = array ();
		
		if ($rs = $this->getMySqlConneter ()->multi_query ( $sql )) {
			if ($rs != null && $rs = $this->getMySqlConneter ()->use_result ()) {
				while ( $row = $rs->fetch_row () ) {
					
					$this->search_dt = $row ['0'];
					$this->mem_id = $row ['1'];
					$this->mem_nm = $row ['2'];
					$this->positions = $row ['3'];
					$this->license_plate = $row ['4'];
					$this->car_id = $row ['5'];
					$this->cusm_cd = $row ['6'];
					$this->brno = $row ['7'];
					$this->attend_tp = $row ['8'];
					
					$this->tablePrint ( $isSuperAdmin );
				}
				$rs->free ();
			}
		}
	}
	public function admin_search4table($table, $category, $value) {
		$sql = "CALL " . self::CONST_DB . ".search('" . $table . "','" . $category . "','" . $value . "');select @out_err_cd, @out_err_msg;";
		// $retval = array ();
		
		if ($rs = $this->getMySqlConneter ()->multi_query ( $sql )) {
			if ($rs != null && $rs = $this->getMySqlConneter ()->use_result ()) {
				while ( $row = $rs->fetch_row () ) {
					$this->search_dt = $row ['0'];
					$this->mem_id = $row ['1'];
					$this->mem_nm = $row ['2'];
					$this->attend_tp = $row ['3'];
					$this->note = $row ['4'];
					
					$this->admin_tablePrint ( $isSuperAdmin );
				}
				$rs->free ();
			}
		}
	}
	public function search4Detail($date, $value) {
		$sql = "CALL " . self::CONST_DB . ".daily_accounts_search('1', '" . $date . "', '','', '" . $value . "');select @out_err_cd, @out_err_msg;";
		// $retval = array ();
		
		if ($rs = $this->getMySqlConneter ()->multi_query ( $sql )) {
			if ($rs != null && $rs = $this->getMySqlConneter ()->use_result ()) {
				while ( $row = $rs->fetch_row () ) {
					$this->search_dt = $row ['0']; // 날짜
					$this->mem_id = $row ['1']; // 사원번호
					$this->mem_nm = $row ['2']; // 이름
					$this->positions = $row ['3']; // 직급
					$this->license_plate = $row ['4']; // 차량등록번호판
					$this->car_id = $row ['5']; // 차량식별번호
					$this->cusm_cd = $row ['6']; // 거래처코드
					$this->brno = $row ['7']; // 근무점포
					$this->attend_tp = $row ['8']; // 출근여부
					$this->subs_amt = $row ['9']; // 용차비용
					$this->subs_firm = $row ['10']; // 용차업체코드
					$this->etc_amt_1 = $row ['11']; // 기타 비용1
					$this->etc_amt_2 = $row ['12']; // 기타 비용2
					$this->close_deduct = $row ['13']; // 휴무공제
					$this->car_soyu_tp = $row ['14'];
					$this->car_soyu_nm = $row ['15'];
					$this->note = $row ['16']; // 메모
				}
				$rs->free ();
			}
		}
	}
	public function createDailyReport($search_dt, $mem_id, $attend_tp, $delivery_cnt, $subs_amt, $subs_firm_cd, $etc_amt_1, $etc_amt_2, $close_deduct, $note) {
		$sql = "CALL " . self::CONST_DB . ".daily_accounts('3','" . $search_dt . "','" . $mem_id . "','" . $attend_tp . "','" . $delivery_cnt . "','" . $subs_amt . "','" . $subs_firm_cd . "','" . $etc_amt_1 . "','" . $close_deduct . "', '" . $etc_amt_2 . "','" . $note . "');select @out_err_cd, @out_err_msg;";
		// echo $sql;
		$rs = $this->getMySqlConneter ()->multi_query ( $sql );
	}
	public function modifyDailyReport($search_dt, $mem_id, $attend_tp, $delivery_cnt, $subs_amt, $subs_firm_cd, $etc_amt_1, $etc_amt_2, $close_deduct, $note) {
		$sql = "CALL " . self::CONST_DB . ".daily_accounts('2','" . $search_dt . "','" . $mem_id . "','" . $attend_tp . "','" . $delivery_cnt . "','" . $subs_amt . "','" . $subs_firm_cd . "','" . $etc_amt_1 . "','" . $etc_amt_2 . "','" . $close_deduct . "','" . $note . "');select @out_err_cd, @out_err_msg;";
		// echo $sql;
		$rs = $this->getMySqlConneter ()->multi_query ( $sql );
	}
}


